package com.example.Service;


import com.example.PO.Order;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class OrderService {
    private List<Order> orders = new ArrayList<>();


    public OrderService() {
        // 示例订单数据，关联客户姓名需存在于CustomerService中
        orders.add(new Order("ORD001", "2023-01-01", "100.00", "2023-01-05",
                "已发货", "已支付", "无备注", "张三"));
    }

    public List<Order> getAllOrders() {
        return orders;
    }

    public void addOrder(Order order) {
        orders.add(order);
    }

    public void updateOrder(Order updatedOrder) {
        for (Order order : orders) {
            if (order.getOrderId().equals(updatedOrder.getOrderId())) {
                order.setOrderDate(updatedOrder.getOrderDate());
                order.setTotal_amount(updatedOrder.getTotal_amount());
                order.setDeliveryDate(updatedOrder.getDeliveryDate());
                order.setOrderStatus(updatedOrder.getOrderStatus());
                order.setPaymentStatus(updatedOrder.getPaymentStatus());
                order.setRemark(updatedOrder.getRemark());
                order.setCustomer(updatedOrder.getCustomer());
                break;
            }
        }
    }

    public void deleteOrder(String orderId) {
        orders.removeIf(order -> order.getOrderId().equals(orderId));
    }

    // 生成唯一订单ID（简单示例）
    private String generateNextOrderId() {
        return "ORD" + (orders.size() + 1);
    }
}